var rootPath = getRootPath();
$(document).ready(function() {
	$("#loginForm").dialog({
		autoOpen : true,
		draggable : false,
		resizable : false,
		width : 350,
		modal : true,
		buttons : {
			"登录" : doLogin
		},
		beforeClose : preventClose
	});

});

function doLogin() {
	var error;
	if ($("#loginName").val().length < 1) {
		error="用户名不能为空";
		
	} else if ($("#password").val().length < 1) {
		error="密码不能为空";
	} else {
		$.getJSON(rootPath + "/login.htm", {
			loginName : $("#loginName").val(),
			password : $("#password").val()
		}, function(data) {
			if(data.success){
				$("#error").removeClass("ui-state-error ui-corner-all ui-icon-alert");
				$("#error").html("登录成功");
				$.getJSON(getRootPath() + "/urlGuide.htm",function(data){
					location.href = getRootPath() +data.uri+".htm";
				});
			}else{
				$("#error").addClass("ui-state-error ui-corner-all ui-icon-alert");
				$("#error").html("用户名或者密码错误");
				return;
			}
		});
	}
	$("#error").addClass("ui-state-error ui-corner-all ui-icon-alert");
	$("#error").html(error);
}

function preventClose() {
	return false;
}